package org.lanqiao.dxzf.controller.admin;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.lanqiao.dxzf.entity.Role;
import org.lanqiao.dxzf.service.admin.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RoleController {
	@Autowired
	RoleService roleService;
    /**
     * 角色管理-->查询角色所有信息
     * @return
     */
    @RequestMapping("/role_list.do")
    public ModelAndView role_list(){
    	ModelAndView modelAndView = new ModelAndView("role/role_list");
    	List<Role> listRole = roleService.find(null);
    	modelAndView.addObject("listRole",listRole);
        return modelAndView;
    }
    /**
     * 角色管理->>角色添加页面
     * @return
     */
    @RequestMapping("/role_add.do")
    public String role_add() {
    	return "role/role_add";
    }
    /**
     * 角色管理->>角色添加操作并授权
     * @return
     */
    @RequestMapping("/addRole.do")
    public String addRole(Role role,HttpServletRequest req) {
    	String[] p = req.getParameterValues("pid");
    	List<Integer> pids = new ArrayList<Integer>();
    	for(int i = 0;i<p.length;i++) {
    		System.out.println(p[i]);
    		pids.add(Integer.parseInt(p[i]));
    	}
    	int b = roleService.insertAndaddPriv(role, pids);
    	return "role/role_add";
    }
    /**
     * 角色管理-->>角色修改页面
     * @return
     */
    @RequestMapping("/role_modi.do")
    public String role_modi() {
    	return "role/role_modi";
    }
    /**
     * 角色管理-->>角色页面的操作
     */
}
